using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using LocalBoard.Domain;
using LocalBoard.Controller;

namespace LocalBoard.Web
{
	/// <summary>
	/// Summary description for RssFeed.
	/// </summary>
	public partial class RssFeed : Page
	{
		private Club _club = null;
		private Board _board = null;

		private void Page_Load(object sender, System.EventArgs e)
		{
			string applicationName = "LocalBoard.Web";
			string channelTitle = "";
			string channelLink = "";
			string channelDescription = "";

			string clubIdString = HttpContext.Current.Request.QueryString["club"];
			if(clubIdString != null && clubIdString.Length > 0)
				_club = new AdminController(Global.AccessorFactory).GetClub(Convert.ToInt32(clubIdString));
			string boardIdString = HttpContext.Current.Request.QueryString["board"];
			if(boardIdString != null && boardIdString.Length > 0)
				_board = new ClubController(_club.Id, Global.AccessorFactory).GetBoard(Convert.ToInt32(boardIdString));

			if(_board != null)
			{
				channelTitle = applicationName + " - " + _club.Name + ": " + this._board.Name;
				channelLink = ClubPage.AddBoardQueryStringToUrl(ClubPage.AddClubQueryStringToUrl("http://localhost/LocalBoard.Web/ViewBoard.aspx", _club.Id), _board.Id)  ;
				channelDescription = _board.Name;
			}
			else
			{
				channelTitle = applicationName + " - " + _club.Name;
				channelLink = ClubPage.AddClubQueryStringToUrl("http://localhost/LocalBoard.Web/ViewClub.aspx", _club.Id);
				channelDescription = _club.Description;
			}
//
//			RssController rssController = new RssController(channelTitle, channelLink, channelDescription, "en-US", "http://localhost/LocalBoard.Web/ViewBoard.aspx?Club={0}&board={1}&message={2}", Global.AccessorFactory);
//
//			Response.Clear();
//			Response.ContentType = "text/XML";
//			if(_board != null)
//				Response.Write(rssController.GetRssOutput(_board));
//			else
//				Response.Write(rssController.GetRssOutput(_club));

			RssController rssController = new RssController(channelTitle, channelLink, channelDescription, "en-US", "http://localhost/LocalBoard.Web/ViewBoard.aspx?Club={0}&board={1}&message={2}", Global.AccessorFactory);

			if(_board != null)
				rssController.ConstructRssFeed(_board);
			else
				rssController.ConstructRssFeed(_club);
			Response.Clear();
			Response.ContentType = "text/xml";
			rssController.WriteRss(Response.OutputStream);
			Response.End();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
